﻿@{
    ViewBag.Title = "原料编辑";
    var product = ViewBag.Product as CubicFWNet.Data.Models.Product;
}

<section class="content-header">
    <h1>
        原料编辑
    </h1>
    <ol class="breadcrumb">
        <li><a href="javascript:void(0);"><i class="fa fa-dashboard"></i>@Resources.Global.PageTitle</a></li>
        <li><a href="@Url.Action("Index","Home")">首页</a></li>
        <li class="active">原料编辑</li>
    </ol>
</section>

<section class="content">
    <form class="form-horizontal" method="post" id="formMain">
        <div class="box box-solid">
            <div class="box-body">
                <div class="row">
                    <input type="hidden" name="ProductID" value="@product.Id" />
                    <input type="hidden" id="modalData" value="@product.Data">
                    <input type="hidden" id="Data" name="Data" />
                    <div class="form-group col-md-6 col-sm-12">
                        <label for="ProductName" class="col-sm-3 control-label">名称</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="ProductName" name="ProductName" value="@product.Name">
                        </div>
                    </div>
                    <div class="form-group col-md-6 col-sm-12">
                        <label for="Number" class="col-sm-3 control-label">编号</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="Number" name="Number" value="@product.Number">
                        </div>
                    </div>


                    <div class="form-group col-md-6 col-sm-12" style="display:none">
                        <label for="Format" class="col-sm-3 control-label">规格</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="Format" name="Format" value="@product.Format" />
                        </div>
                    </div>
                    <div class="form-group col-md-6 col-sm-12">
                        <label for="Pack" class="col-sm-3 control-label">包装单位</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="Pack" name="Pack" value="@product.Pack" />
                        </div>
                    </div>
                    <div class="form-group col-md-6 col-sm-12">
                        <label for="Unit" class="col-sm-3 control-label">基本单位</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="Unit" name="Unit" value="@product.Unit" />
                        </div>
                    </div>
                    <div class="form-group col-md-6 col-sm-12">
                        <label for="Width" class="col-sm-3 control-label">宽度-mm</label>
                        <div class="col-sm-9">
                            <input type="number" class="form-control" id="Width" name="Width" value="@product.SizeWidth" />
                        </div>
                    </div>
                    <div class="form-group col-md-6 col-sm-12">
                        <label for="Length" class="col-sm-3 control-label">长度-mm</label>
                        <div class="col-sm-9">
                            <input type="number" class="form-control" id="Length" name="Length" value="@product.SizeLenth" />
                        </div>
                    </div>
                    <div class="form-group col-md-6 col-sm-12">
                        <label for="Price" class="col-sm-3 control-label">价格</label>
                        <div class="col-sm-9">
                            <input type="number" class="form-control" id="Price" name="Price" value="@product.Price" />
                        </div>
                    </div>

                    <div id="json-content">
                        <div class="form-group col-md-6 col-sm-12" style="display:none">
                            <label for="Quantity" class="col-sm-3 control-label">起订量[PCS]</label>
                            <div class="col-sm-9">
                                <input type="number" class="form-control" id="Quantity" name="Quantity" data-des="起订量[PCS]" value="@product.Quantity" />
                            </div>
                        </div>
                        <div class="form-group col-md-6 col-sm-12">
                            <label for="Color" class="col-sm-3 control-label">颜色</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" id="Color" name="Color" data-des="颜色" maxlength="50" value="@product.Color" />
                            </div>
                        </div>

                    </div>
                </div>

                <div class="row">
                    <div class="form-group col-md-6 col-sm-12">
                        <label for="Explain" class="col-sm-3 control-label">特点</label>
                        <div class="col-sm-9">
                            <textarea rows="3" class="form-control" id="Explain" name="Explain" maxlength="500">@product.Explain</textarea>
                        </div>
                    </div>
                    <div class="form-group col-md-6 col-sm-12">
                        <label for="Memo" class="col-sm-3 control-label">备注</label>
                        <div class="col-sm-9">
                            <textarea rows="3" class="form-control" id="Memo" name="Memo" maxlength="500">@product.Memo</textarea>
                        </div>
                    </div>
                </div>

                <div class="row">
                    <div class="form-group col-md-6 col-sm-12">
                        <label for="Creator" class="col-sm-3 control-label">创建人</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="Creator" name="RealName" value="@product.CreatorName" readonly="readonly" />
                        </div>
                    </div>
                    <div class="form-group col-md-6 col-sm-12">
                        <label for="CreateTime" class="col-sm-3 control-label">创建时间</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" id="CreateTime" value="@product.CreateTime" readonly="readonly" />
                        </div>
                    </div>
                </div>

            </div>
            <div class="box-footer">
                <div class="box-footer">
                    <span class="btn btn-primary" onclick="FormSub()">确 定</span>&nbsp;&nbsp;&nbsp;&nbsp;
                    <a class="btn btn-primary" href="@Url.Action("Index","Material")">返 回</a>
                </div>
            </div>
        </div>
    </form>
</section>

@section Scripts {
    <script type="text/javascript">
        //$(document).ready(function () {
        //    //解析Data数据
        //    var data = JSON.parse(document.getElementById("modalData").value);
        //    var $content = $('#json-content');
        //    var html = "";
        //    data.forEach(function (e, i) {
        //        if (typeof e.value == "undefined") {
        //            e.value = "";
        //        }
        //        if (typeof e.name == "undefined") {
        //            e.name = "";
        //        }
        //        if (typeof e.des == "undefined") {
        //            e.des = "未知";
        //        }
        //        html += "<div class='form-group col-md-6'>";
        //        html += "<label for='j_a' class='col-sm-3 control-label'>" + e.des + "</label>";
        //        html += "<div class='col-sm-9'>";
        //        html += "<input type='text' class='form-control' data-des='" + e.des + "' id='" + e.name + "' name='" + e.name + "' value='" + e.value + "' >";
        //        html += "</div></div>";
        //    });
        //    $content.append(html);
        //})


        //保存Data数据
        //function getParam() {
        //    var postdata = [];
        //    //主键
        //    $("#json-content").find('input,select,textarea').each(function (r) {
        //        var $this = $(this);
        //        var id = $this.attr('id');
        //        var type = $this.attr('type');
        //        if (id) {
        //            switch (type) {
        //                case "checkbox":
        //                    postdata.push({ des: $this.attr("data-des"), name: id, value: $this.is(":checked") });
        //                    break;
        //                case "select":
        //                    var value = $this.find("option:selected").val() == "" ? null : $this.find("option:selected").val();
        //                    postdata.push({ des: $this.attr("data-des"), name: id, value: value });
        //                    break;
        //                default:
        //                    var value = $this.val() == "" ? "&nbsp;" : $this.val();
        //                    postdata.push({ des: $this.attr("data-des"), name: id, value: value });
        //                    break;
        //            }
        //        }
        //    });
        //    return JSON.stringify(postdata);
        //}

        //提交表单
        function FormSub() {
            var name = $("#ProductName").val().trim();
            if (name == "") {
                $.modalAlert("请输入名称", "warning");
                return false;
            }

            var number = $("#Number").val().trim();
            if (number == "") {
                $.modalAlert("请输入编号", "warning");
                return false;
            }

            var width = $("#Width").val().trim();
            if (width == "") {
                $.modalAlert("请输入宽度", "warning");
                return false;
            }

            var length = $("#Length").val().trim();
            if (length == "") {
                $.modalAlert("请输入长度", "warning");
                return false;
            }

            var price = $("#Price").val().trim();
            if (price == "") {
                $.modalAlert("请输入价格", "warning");
                return false;
            }

            //var data = getParam();
            //$("#Data").val(data);
            $("#formMain").submit();
        }
    </script>
}